package cn.tedu.boot.ers.util;

import org.springframework.util.DigestUtils;

import java.util.UUID;

public class PasswordUtils {
    // TODO 加密过程
    public static String encodePassword(String password) {
        String salt = UUID.randomUUID().toString().substring(0,9);
        String encodePassword = DigestUtils.md5DigestAsHex(password.getBytes());
        encodePassword = salt + encodePassword;
        System.out.println(encodePassword);
        return encodePassword;
    }

    public static boolean matches(String password, String encodePassword) {
        String salt = encodePassword.substring(0, 9);
        String newPassword = DigestUtils.md5DigestAsHex(password.getBytes());
        newPassword = salt + newPassword;
        System.out.println(newPassword);
        return newPassword.equals(encodePassword);
    }
}

